package com.csw.rabbitmq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class RabbitMqSend {
    private Logger logger = LoggerFactory.getLogger(RabbitMqSend.class);

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Async
    public void postInsertQuene(SendEntity sendEntity) {
        rabbitTemplate.convertAndSend(TopicExchangeBindingQueue.YGZS_POST_INSERT_QUEUE_EXCHANGE_NAME,
                TopicExchangeBindingQueue.ROUTE_KEY_YGZS_POST_INSERT, sendEntity, message -> {
                    return message;
                }, new CorrelationData(UUID.randomUUID().toString()));
    }
}
